/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
#include <string>
#include <unordered_map>
#include <cmath>

bool is_prime(int n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) return false;
    }
    return true;
}

int next_prime(int n) {
    while (!is_prime(n))
        n++;
    return n;
}

int previous_prime(int n) {
    while (!is_prime(n))
        n--;
    return n;
}

int main() {
    std::unordered_map<std::string, int> word_to_digit = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };
    
    std::string word1, word2, word3;
    std::cin >> word1 >> word2 >> word3;
    
    if (word_to_digit.find(word1) == word_to_digit.end() || 
        word_to_digit.find(word2) == word_to_digit.end() || 
        word_to_digit.find(word3) == word_to_digit.end()) {
        std::cout << "Wrong input";
        return 0;
    }
    
    int number = word_to_digit[word1] * 100 +
                 word_to_digit[word2] * 10 +
                 word_to_digit[word3];
    
    if (number < 100 || number > 999) {
        std::cout << "Wrong input";
        return 0;
    }
    
    int next = next_prime(number);
    int previous = previous_prime(number - 1);
    
    // Output the nearest prime number
    // If two prime numbers are equally near, output the smaller prime number
    if (number - previous <= next - number) {
        std::cout << previous;
    } else {
        std::cout << next;
    }
    return 0;
}